import { useMemo } from 'react'

function useFields(fields) {
  if (Object.keys(fields).length === 0) return []

  return useMemo(() => {
    const { row = [], col = [] } = fields
    const colMeas = col.filter((v) => v.fieldClassify === 'measure')
    console.log(row, col)
    return {
      rows: row.map((v) => v.id),
      columns: col.map((v) => v.id),
      values: colMeas.map((v) => v.id),
      valueInCols: !!colMeas.length
    }
  }, [fields])
}

export default useFields
